import random

print('*'*30)
print('*        中国工商银行          *')
print('*        账户管理系统          *')
print('*'*30)
print()
print('*1.开户                      *')
print('*2.存钱                      *')
print('*3.取钱                      *')
print('*4.转账                      *')
print('*5.查询                      *')
print('*6.Bye！                     *')
print('*'*30)

users=dict()
def add_user(user):
    if user['姓名'] in users.keys():
         return 2
    if len(users)<101:
        users[userName]=user
        return 1
    else:
        return 3
def save_money(username):
    if username in users.keys():
        save = dict()
        moneys=0
        save = users[username]
        print(save)
        i=int(input("请输入存款额："))
        moneys = save['余额']
        moneys=moneys+i
        save['余额']=moneys
        users.update({save['姓名']:save})
        print(users)
        return 1
    else:
        return 0

def take_money(username):
    if username in users.keys():
        save = dict()
        moneys=0
        save = users[username]
        print(save)
        ss=input("请输入账户:")
        pwd=input("请输入密码:")
        if ss==save['账户'] and pwd==save['密码']:
            i=int(input("请输入取款额："))
            if i>save['余额']:
                return 3
            else:
                moneys = save['余额']
                moneys=moneys-i
                save['余额']=moneys
                users.update({save['姓名']:save})
                print(users)
                return 1
        else:
            return 2
    else:
        return 0

def exchange_money(username):
    if username in users.keys():
        save1 = dict()
        moneys1 = 0
        save1 = users[username]
        print(save1)
        ss = input("请输入您的账户:")
        pwd = input("请输入您的密码:")
        if ss == save1['账户'] and pwd == save1['密码']:
            he_name=input("请输入他的姓名:")
            he_s=input("请输入他的账户:")
            save2 = dict()
            moneys2 = 0
            save2 = users[he_name]
            print(save2)
            if he_name==save2['姓名'] and he_s==save2['账户']:
                i = int(input("请输入转账额："))
                if i>save1['余额']:
                    return 3
                else:
                    moneys1 = save1['余额']
                    moneys1 = moneys1 - i
                    save1['余额'] = moneys1
                    users.update({save1['姓名']: save1})
                    moneys2 = save2['余额']
                    moneys2 = moneys2 + i
                    save2['余额'] = moneys2
                    users.update({save2['姓名']: save2})
                    print(users)
                    return 0
            return 1
        else:
            return 2
    else:
        return 0

def select_user(username,password):
    if username in users.keys():
        save = dict()
        moneys = 0
        save = users[username]
        if password==save['密码']:
            return 1
        else:
            return 2
    else:
        return 0

while 1:
    o=input("请输入你要操作的内容：")
    if o=='1':
        user=dict()
        userName = input("请输入姓名：")
        password = input("请输入密码：")
        location = input("地址：国家、省份、街道、门牌号:")
        s = str()
        for i in range(8):
            a = random.randint(0, 9)
            s = s + str(a)
        print(s)
        user.update({'姓名':userName,'账户':s,'密码':password,'地址':location})
        result=add_user(user)
        if result==1:
            print("成功")
            money = int(input('请输入存款额：'))
            bankName = '中国工商银行'
            user.update({'余额':money,'开户行':bankName})
            users[user['姓名']] = user
            print(users[user['姓名']])
        elif result==2:
            print("用户已存在")
        else:
            print("用户库满")
    if o=='2':
        username=input("请输入姓名:")
        result= save_money(username)
        if result==1:
            print('成功')
        if result==0:
            print('用户不存在')
    if o=='3':
        username = input("请输入姓名:")
        result = take_money(username)
        if result == 1:
            print('成功')
        if result == 0:
            print('用户不存在')
        if result==2:
            print("密码错误")
        if result==3:
            print("钱不够")
    if o=='4':
        username = input("请输入您的姓名:")
        result = exchange_money(username)
        if result == 0:
            print('成功')
        if result == 1:
            print('用户不存在')
        if result == 2:
            print("密码错误")
        if result==3:
            print("钱不够")
    if o=='5':
        username=input("请输入姓名")
        password=input("请输入密码")
        result=select_user(username,password)
        if result==0:
            print("用户不存在")
        if result==1:
            print(users[username])
        if result==2:
            print("密码错误")

    if o=='6':
        break